<template>
	<view>
		<view class="orders">
			<view class="order" v-for="(item, index) of orderList" :key="item.orderId">
				<view class="h">
					<view class="l">订单编号：{{item.orderId}}</view>
					<!-- <view class="r">{{item.orderName}}</view> -->
				</view>
				<view class="goods" v-for="(iitem, iindex) of item.orderItems" :key="iitem.productId" :data-index="iindex">
					<view class="img">
						<image :src="iitem.orginalImageUrl" />
					</view>
					<view class="info">
						<text class="name uni-ellipsis">{{iitem.productName}}</text>
						<text class="name uni-ellipsis" v-if="iitem.productFeatureApplDesc">{{iitem.productFeatureApplDesc}}</text>
						<!-- <text class="number">共{{iitem.quantity}}件商品</text> -->
						<view class="uni-flex uni-row bottom">
							<view class="text price" style="flex: 1;">￥{{iitem.unitListPrice}}</view>
							<view class="text number" style="flex: 1;">X{{iitem.quantity}}</view>
						</view>
					</view>
					<view class="status"></view>
				</view>
				<view class="b">
					<view class="l">实付：￥{{item.grandTotal}}</view>
					<view class="r">
						<button class="btn" :data-order-index="index" @click="payOrder" v-if="item.statusId=='ORDER_WAIT_PAY'">去付款</button>
						<button class="btn" :data-order-index="index" @click="viewOrderStatus" v-if="item.statusId=='PROCESSING'">查看订单信息</button>
						<button class="btn" :data-order-index="index" @click="viewLogistics" v-if="item.statusId=='SENT'">物流信息</button>
						<button class="btn" :data-order-index="index" @click="viewLogistics" v-if="item.statusId=='ORDER_DELIVERYD'">物流信息</button>
						<button class="btn" :data-order-index="index" @click="waitComments" v-if="item.statusId=='ORDER_DELIVERYD'">去评价</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {getOrders} from '@/api/buy/order';
	import {
		getUrl
	} from '@/common/oss';
	import {
		mapGetters
	} from 'vuex'
	
	export default {
		data() {
			return {
				orderList: [],
				page: 1,
				pageSize: 4,
				baseUrl: "",
			}
		},
		onLoad(e) {
			this.loadOrder();
		},
		onReachBottom() {
			this.loadOrder()
		},
		onUnload :function(){
			this.orderList = [];
			this.page = 1;
		},
		computed:{
		...mapGetters(
			["userId"]
		)},
		mounted() {
			console.log(this.userId)
		},
		methods: {
			loadOrder() {
				getOrders(this.getParameters()).then(response => {
//					console.log(JSON.stringify(response));
					if(response.status == 200) {
						this.baseUrl = getUrl();
						this.orderList = this.orderList.concat(response.data) 
						this.page++;
					}
				});
			},
			getParameters() {
				return {
					page: this.page,
					limit: this.pageSize,
					partyId: this.userId,
					orderBy: "createdStamp",
					orderTypeId: "SALES_ORDER",
					sort: "desc"
				};
			},
			waitComments(event) {
				let orderIndex = event.mp.currentTarget.dataset.orderIndex;

			},
			viewLogistics(event) {
				let orderIndex = event.mp.currentTarget.dataset.orderIndex;
			},
			viewOrderStatus(event) {
				let orderIndex = event.mp.currentTarget.dataset.orderIndex;
				uni.navigateTo({
					url:"/pages/buy/orderDetail?id="+this.orderList[orderIndex].orderId
				})
			},
			payOrder(event) {
				let orderIndex = event.mp.currentTarget.dataset.orderIndex;
				
				setStore({
					name: '$sc_temp_order',
					content: this.orderList[orderIndex],
					type: 'session'
					})
				
				uni.navigateTo({
					url: "/pages/buy/checkout?typeId="+1
				})
			}
		}
	}
</script>

<style>
	.orders {
		height: auto;
		width: 750upx;
		overflow: hidden;
	}

	.order {
		margin-top: 20upx;
		background: #fff;
	}

	.order .h {
		height: 83.3upx;
		line-height: 83.3upx;
		margin-left: 31.25upx;
		padding-right: 31.25upx;
		border-bottom: 1upx solid #f4f4f4;
		font-size: 30upx;
		color: #333;
	}

	.order .h .l {
		float: left;
	}

	.order .h .r {
		float: right;
		color: #b4282d;
		font-size: 24upx;
	}

	.order .goods {
		display: flex;
		align-items: center;
		height: 199upx;
		margin-left: 31.25upx;
	}

	.order .goods .img {
		height: 145.83upx;
		width: 145.83upx;
		background: #f4f4f4;
	}

	.order .goods .img image {
		height: 145.83upx;
		width: 145.83upx;
	}

	.order .goods .info {
		height: 145.83upx;
		flex: 1;
		padding-left: 20upx;
	}

	.order .goods .name {
		display: block;
		width: 100%;
		height: 44upx;
		line-height: 44upx;
		color: #333;
		font-size: 30upx;
	}
	.order .goods .bottom {
		margin-top: 68upx;
		height: 37upx;
		line-height: 37upx;
		font-size: 25upx;
	 }
	 
	 .price {
		 color: #E51C23;
	 }
	 
	 .number {
		 right: 10px;
		 color: #666;
	 }

	/* .order .goods .number {
		margin-top: 68upx;
		display: block;
		height: 37upx;
		line-height: 37upx;
		color: #666;
		font-size: 25upx;
	} */

	.order .goods .status {
		width: 105upx;
		color: #b4282d;
		font-size: 25upx;
	}

	.order .b {
		height: 103upx;
		line-height: 103upx;
		margin-left: 31.25upx;
		padding-right: 31.25upx;
		border-top: 1upx solid #f4f4f4;
		font-size: 30upx;
		color: #333;
	}

	.order .b .l {
		float: left;
	}

	.order .b .r {
		float: right;
	}

	.order .b .btn {
		margin-top: 19upx;
		height: 64.5upx;
		line-height: 64.5upx;
		text-align: center;
		padding: 0 20upx;
		border-radius: 5upx;
		font-size: 28upx;
		color: #fff;
		background: #b4282d;
	}
</style>
